Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support sidebarAbsolutePath to fix relative link and nested sidebar when I just provide one sidebar.md #1076

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

tangshuang
Copy link

Summary

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Docs
  • Build-related changes
  • Other, please describe:

If changing the UI of default theme, please provide the before/after screenshot:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

  • When resolving a specific issue, it's referenced in the PR's title (e.g. fix #xxx[,#xxx], where "xxx" is the issue number)

You have tested in the following browsers: (Providing a detailed version will be better.)

  • Chrome
  • Firefox
  • Safari
  • Edge
  • IE

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature
  • Related documents have been updated
  • Related tests have been updated

To avoid wasting your time, it's best to open a feature request issue first and wait for approval before working on it.

Other information:

Referer to issues:


  • DO NOT include files inside lib directory.

Copy link
Member

@anikethsaha anikethsaha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix the CI error

@tangshuang
Copy link
Author

@anikethsaha I’m sorry, I did not find the way to fix. Could you please have a look to this problem?

@anikethsaha
Copy link
Member

its because you added a header ## in configuration.md docs. so, the fixtures need to be changed.

add sidebarAbsolutePath in array here

@tangshuang
Copy link
Author

its because you added a header ## in configuration.md docs. so, the fixtures need to be changed.

add sidebarAbsolutePath in array here

Fixed. Thanks!

@anikethsaha
Copy link
Member

I will review this soon

@anikethsaha anikethsaha self-assigned this Mar 19, 2020

// auto alias sidebar which is set to be absolute path
if (config.sidebarAbsolutePath) {
const sidebar = config.loadSidebar || '_sidebar.md';
Copy link
Member

@trusktr trusktr Apr 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this sidebarAbsolutePath option? Or can we just provide an absolute path in loadSidebar? We can use a url tool to detect absolute path, like /path/to/sidebar.md, //path/to/sidebar.md, https://example.com/path/to/sidebar.md, etc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think about this: what happend if they set sidebarAbsolutePath to true, but it isn't an absolute path? Should it be an error? Will they be confused?

Here's an idea on how to detect absolute paths with a regex: https://stackoverflow.com/a/19709846/454780 (but we should allow paths starting with / to return true if we want.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's an idea on how to detect absolute paths with a regex: https://stackoverflow.com/a/19709846/454780 (but we should allow paths starting with / to return true if we want.

Yes, we should consider detecting too.

It should works with `loadSidebar`. If you do not set `loadSidebar`, don't set this option any more.

It works well with `relativePath` and `basePath`. You do not need to worry about the path conflict.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These docs don't describe what the option actually does. It doesn't mention that it can be a string. Can you please update?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @trusktr. There also seems to be some gramma thats not correct

Copy link
Member

@trusktr trusktr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good idea. But we need some changes:

  • just use one variable for this if possible, loadSidebar, and detect all absolute paths. Is there a reason not to use one option for this case?
  • Make sure the docs describe the option in full. At the moment it is not clear what to do with the option, it doesn't mention anything about the string values.

@anikethsaha
Copy link
Member

thanks @trusktr for the detailed review.
just to add a point, this will be a part of v5 cause I dont think we can do any feature or enhancement release as of now, it all should be released with v5 if this gets approved.

@anikethsaha
Copy link
Member

I will create a v5 branch soon or will need to discuss where to start the development and how.

@woss woss mentioned this pull request May 30, 2020
1 task
@anikethsaha anikethsaha removed their assignment May 30, 2020
@anikethsaha anikethsaha requested a review from trusktr May 30, 2020 13:32
Copy link
Contributor

@arelstone arelstone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job on this, this is a feature that some users could defiantly use.. There is a few things i would suggest changed.

You've rearranged some imports that I don't think it necessary. The less files that is changed in a PR the easier it is to be get reviewed. I would suggest that you reverted the files that only has import changes to the previous state.

It should works with `loadSidebar`. If you do not set `loadSidebar`, don't set this option any more.

It works well with `relativePath` and `basePath`. You do not need to worry about the path conflict.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @trusktr. There also seems to be some gramma thats not correct

@@ -1,13 +1,13 @@
import { readFileSync } from 'fs';
import { resolve, basename } from 'path';
import resolvePathname from 'resolve-pathname';
import fetch from 'node-fetch';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be reverted to the previous state. There is no point in rearranging imports if this is the only changes in the file

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a result of the automated husky lint process, which modifies the files. The git commit step should not leave modifications in the working tree.

!config.ignore
) {
if (href === compilerClass.config.homepage) {
const sidebarAbsolutePath = compiler.config.sidebarAbsolutePath;
const basePath =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me the following lines has a weird formatting.

I would suggest doing this instead:

Suggested change
const basePath =
const basePath = typeof sidebarAbsolutePath === 'string'
? sidebarAbsolutePath
: router.getBasePath();
const relativeTo = isSidebar && sidebarAbsolutePath
? basePath
: router.getCurrentPath();

Copy link
Member

@trusktr trusktr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @tangshuang for this idea!

We should make a function called isAbsolute, and we can use this along with out new isExternal function: if the condition isExternal(url) || isAbsolute(url) is true, we can automatically treat the URL the same way as proposed in this PR, but without having to have a new sidebarAbsolutePath option.

The more combinations of options we need to have, the more difficult it is for the user to understand and easier to get it wrong.

just to add a point, this will be a part of v5 cause I dont think we can do any feature or enhancement release as of now, it all should be released with v5 if this gets approved.

I believe for non-breaking changes we can release them in v4.x until we're ready for v5.

You've rearranged some imports that I don't think it necessary. The less files that is changed in a PR the easier it is to be get reviewed. I would suggest that you reverted the files that only has import changes to the previous state.

I agree with this in general, though as I mentioned in the other comment it is a result of the automated commit hook. EDIT: a recent fix automatically commits the changes (see #1108). Once things are in good shape, this won't happen anymore. We should make the automated tests fail for any such changes, to make them required (otherwise, let's remove the automated changes from the commit hook).

@anikethsaha @arelstone Let's take on this pull request ourselves unless @tangshuang will return to make the changes before we do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants